/*
* $Id: ChangeQBParamOperation.cpp 169 2010-10-16 17:46:54Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2010 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "ChangeQBParamOperation.h"
#include "../SqlBinder.h"
#include "../Tables/TableNames.h"

CChangeQBParamOperation::CChangeQBParamOperation(){}
CChangeQBParamOperation::~CChangeQBParamOperation(){}

CChangeQBParamOperation::content::content(){
	Clear();
}

void CChangeQBParamOperation::content::Clear(){
	s_type = QueenBee::DEFAULT;
	s_nIdFamily = 0;
	s_nIdParent = 0;
	s_nId = 0;
}

void CChangeQBParamOperation::UpdateValue(IDatabase* pDatabase){
	if(m_content.s_type == QueenBee::DEFAULT)
		return;
	CSqlBinder binder;
	std::tstring strRequest(_T("UPDATE "));
	strRequest = strRequest + QUEEN_BEE_TABLE_NAME + _T(" SET ");
	if(m_content.s_type == QueenBee::FAMILY){
		binder.SetValue(0, m_content.s_nIdFamily);
		strRequest = strRequest + _T("id_family=?");
	}else if(m_content.s_type == QueenBee::PARENT){
		binder.SetValue(0, m_content.s_nIdParent);
		strRequest = strRequest + _T("id_parent_queen_bee=?");
	}
	binder.SetValue(1, m_content.s_nId);
	binder.SetRequest(strRequest + _T(" WHERE id_queen_bee=?;"));
	pDatabase->ExecRequest(binder.GetRequest());
	m_content.Clear();
}
